#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
#include <stdlib.h>

struct student
{
	int id;
	char name[10];
	float score;
};

int main()
{
	char sql[100] = {"select * from student"};
	MYSQL *res = NULL,*con = NULL;
	int ret = 0;

	con = mysql_init(NULL);

	res = mysql_real_connect(con,"localhost","root","123","company",0,NULL,0);
	if(res == NULL)
	{
		printf("%s\n",mysql_error(con));
		exit(-1);
	}

	printf("connect is success\n");


	ret = mysql_query(con,sql);
	if(ret != 0)
	{
		printf("%s\n",mysql_error(con));
		mysql_close(con);
		exit(-1);
	}


	MYSQL_RES *res1 = NULL;
	MYSQL_ROW row = NULL;

	//res1 = mysql_use_result(con);
	res1 = mysql_store_result(con);
	if(res1 == NULL)
	{
		printf("%s\n",mysql_error(con));
		mysql_close(con);
		exit(-1);
	}

	/*
	row = mysql_fetch_row(res1);
	printf("%s %s %s\n",row[0],row[1],row[2]);
	row = mysql_fetch_row(res1);
	printf("%s %s %s\n",row[0],row[1],row[2]);
*/
	/*
	row = mysql_fetch_row(res1);
	while(row != NULL)
	{
		printf("%s %s %s\n",row[0],row[1],row[2]);
		row = mysql_fetch_row(res1);
	}*/

	printf("%lld\n",mysql_num_rows(res1));
	printf("%d\n",mysql_num_fields(res1));
	printf("%d\n",mysql_field_count(con));

	mysql_free_result(res1);

	mysql_close(con);

	return 0;
}
